define([
	"jquery",
	"baseview",
	"text!static/pages/super/tpl/ncmenu.tpl.html",
	"common",
	"knockout",
	"bstreetable"
], function(
	$,
	BaseView,
	template,
	Common,
	ko,
	jqtreetable
) {
	var self;
	var view = BaseView.extend({
		setTemplate: function() {
			this.el.html("").html(template);
			Common.breadcrumb()
		},
		fireEvents: function() {
			var enterpriseId = Common.userContext().enterpriseId;
			this.loadProductClassDataTable(enterpriseId);
		},
		loadProductClassDataTable: function() {
			self = this;
			//ajax请求，
			Common.wrapajax({
				url: Common.baseUrl + "/ncmenu/all",
				contentType: "application/x-www-form-urlencoded",
				type: "post",
				data: {
					ucode: Common.userContext().ucode
				},
				success: function(data) {
					var trdata = [];
					for(var i = 0; i < data.length; i++) {
						var it = {
							id: data[i].menuitemcode,
							pid: data[i].parent_code,
							name: data[i].menuitemname,
							funcode: data[i].funcode || '',
							path: ''
						};
						trdata.push(it);
					}
					$("#bs-treeetable").bstreetable({
						data: trdata,
						maintitle: "NC菜单名称",
						extfield: [{
							title: "路由",
							key: "path",
							type: "input"
						}],
						nodeaddCallback: function(data, callback) {
							alert(JSON.stringify(data));
							//do your things then callback 新增的时候会返回一个字段叫pinnercode,表示父节点的innercode
							callback({
								id: 18,
								name: data.name,
								innercode: "ttttt",
								pid: data.pid
							});
						},
						noderemoveCallback: function(data, callback) {
							alert(JSON.stringify(data));
							//do your things then callback
							callback();
						},
						nodeupdateCallback: self.viewmodel.update
					});
				}
			});
		},
		viewmodel: {
			el: "#ncmenutree",
			ncmenuDataTable: new $.DataTable({
				params: {},
				meta: {
					'menuitemname': {},
					'funcode': {},
					'menuitemcode': {},
					'parent_code': {},
				}
			})
		},
		events: {},
		bindEvents: function() {

		}
	});

	return view;

})